package com.neusoft.hifly.information.article.service.impl;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.neusoft.hifly.commons.exception.SystemErrorException;
import com.neusoft.hifly.commons.lang.LongUtil;
import com.neusoft.hifly.commons.lang.StringConstants;
import com.neusoft.hifly.commons.web.WebUtil;
import com.neusoft.hifly.core.basic.service.impl.CTSaaSBaseServiceImpl;
import com.neusoft.hifly.core.log.annotation.LogType;
import com.neusoft.hifly.core.log.annotation.OperationLog;
import com.neusoft.hifly.core.token.TokenContextHolder;
import com.neusoft.hifly.core.utils.GlobalConstants;
import com.neusoft.hifly.dynamicds.multi.annotation.MultiDynamicRoutingDataSource;
import com.neusoft.hifly.information.article.dao.IArtToColDao;
import com.neusoft.hifly.information.article.dao.IArticleDao;
import com.neusoft.hifly.information.article.dao.IArticleExtDao;
import com.neusoft.hifly.information.article.dao.IArticleInfoDao;
import com.neusoft.hifly.information.article.entity.ArtToColObj;
import com.neusoft.hifly.information.article.entity.ArticleExtObj;
import com.neusoft.hifly.information.article.entity.ArticleInfoObj;
import com.neusoft.hifly.information.article.entity.ArticleLogObj;
import com.neusoft.hifly.information.article.entity.ArticleObj;
import com.neusoft.hifly.information.article.service.IArticleLogService;
import com.neusoft.hifly.information.article.service.IArticleService;
import com.neusoft.hifly.information.column.dao.IColumnDao;
import com.neusoft.hifly.information.column.entity.ColumnObj;
import com.neusoft.hifly.information.view.entity.ArticleViewObj;
import com.neusoft.hifly.information.view.service.IArticleViewService;

/**
 * Title: 文章资讯服务
 * <p>
 * Description: 文章 Service
 * <p>
 * Copyright: 2019
 * <p>
 * Company: 东软汉枫
 *
 * @author lh_neu
 * @version 1.0.0
 */
@Service
@MultiDynamicRoutingDataSource
public class ArticleServiceImpl extends CTSaaSBaseServiceImpl implements IArticleService {
	@Autowired(required = false)
	private IColumnDao columnDao;
	@Autowired(required = false)
	private IArticleDao articleDao;
	@Autowired(required = false)
	private IArticleInfoDao articleInfoDao;
	@Autowired(required = false)
	private IArticleExtDao articleExtDao;
	@Autowired(required = false)
	private IArtToColDao artToColDao;
	@Autowired(required = false)
	private IArticleLogService articleLogService;
	@Autowired(required = false)
	private IArticleViewService articleViewService;

	/**
	 * 保存对象
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param obj
	 *            对象
	 * @param saveOnly
	 *            仅保存
	 * @throws SystemErrorException
	 *             自定义异常
	 */
	@Override
	@OperationLog(method = LogType.UPDATE, msg = "文章")
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class })
	public void saveOrUpdate(final String organCode, final long organLogicId, final ArticleObj obj,
			final boolean saveOnly) throws SystemErrorException {
		if (StringUtils.isEmpty(organCode) || obj == null) {
			return;
		}
		if (StringUtils.isEmpty(obj.getOrganCode())) {
			obj.setOrganCode(organCode);
		}

		if (LongUtil.isEmpty(obj.getOrganLogicId())) {
			obj.setOrganLogicId(organLogicId);
		}

		if (LongUtil.isEmpty(obj.getColumnLogicId())) {
			throw new SystemErrorException("栏目不能为空!");
		}

		final ColumnObj column = columnDao.getByLogicId(organCode, organLogicId, obj.getColumnLogicId());
		if (column == null) {
			throw new SystemErrorException("标题不存在!");
		}

		obj.setColumnName(column.getName());

		if (StringUtils.isEmpty(StringUtils.trimToEmpty(obj.getTitle()))) {
			throw new SystemErrorException("标题不能为空!");
		}

		final ArticleObj oldObj = articleDao.getByLogicId(organCode, organLogicId, obj.getLogicId());

		obj.setOrganLogicId(organLogicId);

		ArticleInfoObj info = obj.getInfo();
		if (info == null) {
			info = new ArticleInfoObj();
		}

		ArticleExtObj ext = obj.getExt();
		if (ext == null) {
			ext = new ArticleExtObj();
		}

		// 有ID的话要判断是否保存还是更新
		if (oldObj == null) {
			// 保存

			obj.setId(idWorker.nextId());

			if (LongUtil.isEmpty(obj.getLogicId())) {
				obj.setLogicId(idWorker.nextId());
			}
			obj.setUpdateTime(LocalDateTime.now());

			if (StringUtils.isEmpty(obj.getUpdatePerson())) {
				obj.setUpdatePerson(TokenContextHolder.get().getUserName());
			}
			obj.setCreateTime(LocalDateTime.now());
			obj.setUpdateTime(LocalDateTime.now());

			if (StringUtils.isEmpty(obj.getCreatePerson())) {
				obj.setCreatePerson(TokenContextHolder.get().getUserName());
			}

			if (LongUtil.isEmpty(obj.getCreatePersonId())) {
				obj.setCreatePersonId(TokenContextHolder.get().getUserLogicId());
			}
			this.setForm(obj, obj);

			if (saveOnly) {
				obj.setStatus(ArticleObj.STATUS_0); // 待编辑
			} else {
				if (column != null) {
					// 提交文章时，根据选择栏目判断下步流程
					if (ColumnObj.APPROVE_RULE_0.equals(column.getApproveRule())) {
						// 不走流程
						obj.setStatus(ArticleObj.STATUS_3); // 发布
					} else if (ColumnObj.APPROVE_RULE_1.equals(column.getApproveRule())) {
						// 只走编审流程
						obj.setStatus(ArticleObj.STATUS_1); // 校对
					} else if (ColumnObj.APPROVE_RULE_2.equals(column.getApproveRule())) {
						// 走编校审流程
						obj.setStatus(ArticleObj.STATUS_1); // 校对
					}
				}
			}

			articleDao.insert(obj);

			info.setOrganCode(obj.getOrganCode());
			info.setOrganLogicId(obj.getOrganLogicId());
			info.setArticleLogicId(obj.getLogicId());
			ext.setOrganCode(obj.getOrganCode());
			ext.setOrganLogicId(obj.getOrganLogicId());
			ext.setArticleLogicId(obj.getLogicId());

			if (info != null) {
				articleInfoDao.insert(info);
			}

			if (ext != null) {
				articleExtDao.insert(ext);
			}

		} else {
			// 更新

			this.setForm(obj, oldObj);

			oldObj.setUpdateTime(LocalDateTime.now());
			if (StringUtils.isEmpty(oldObj.getUpdatePerson())) {
				oldObj.setUpdatePerson(TokenContextHolder.get().getUserName());
			}

			if (saveOnly) {
				obj.setStatus(oldObj.getStatus()); // 文章之前的状态
			} else {
				if (column != null) {
					// 提交文章时，根据选择栏目判断下步流程
					if (ColumnObj.APPROVE_RULE_0.equals(column.getApproveRule())) {
						// 不走流程
						obj.setStatus(ArticleObj.STATUS_3); // 发布
					} else if (ColumnObj.APPROVE_RULE_1.equals(column.getApproveRule())) {
						// 只走编审流程
						obj.setStatus(ArticleObj.STATUS_2); // 审核
					} else if (ColumnObj.APPROVE_RULE_2.equals(column.getApproveRule())) {
						// 走编校审流程
						if (ArticleObj.STATUS_1.equals(oldObj.getStatus())) {
							obj.setStatus(ArticleObj.STATUS_1); // 校对
						} else if (ArticleObj.STATUS_1.equals(oldObj.getStatus())) {
							obj.setStatus(ArticleObj.STATUS_2); // 审核
						} else {
							obj.setStatus(ArticleObj.STATUS_1); // 校对
						}
					}
				}
			}

			articleDao.updateById(oldObj);

			info.setOrganCode(obj.getOrganCode());
			info.setOrganLogicId(obj.getOrganLogicId());
			info.setArticleLogicId(obj.getLogicId());
			ext.setOrganCode(obj.getOrganCode());
			ext.setOrganLogicId(obj.getOrganLogicId());
			ext.setArticleLogicId(obj.getLogicId());

			if (info != null) {
				final UpdateWrapper<ArticleInfoObj> updateWrapper = new UpdateWrapper<>();
				updateWrapper.eq("ORGAN_LOGIC_ID", info.getOrganLogicId());
				updateWrapper.eq("ARTICLE_LOGIC_ID", info.getArticleLogicId());
				articleInfoDao.update(info, updateWrapper);
			}

			if (ext != null) {
				final UpdateWrapper<ArticleExtObj> updateWrapper = new UpdateWrapper<>();
				updateWrapper.eq("ORGAN_LOGIC_ID", ext.getOrganLogicId());
				updateWrapper.eq("ARTICLE_LOGIC_ID", ext.getArticleLogicId());
				articleExtDao.update(ext, updateWrapper);
			}

		}

		/* 更新文章与栏目关联 */
		// 先删除所有关联
		artToColDao.deleteByArticleLogicId(organCode, organLogicId, obj.getLogicId());

		// 保存当前栏目与文章关联关系
		if (LongUtil.isEmpty(obj.getColumnLogicId())) {
			artToColDao
					.insert(new ArtToColObj(organLogicId, obj.getLogicId(), obj.getColumnLogicId(), obj.getMyOrder()));
		}

	}

	/**
	 * 批量提交校对、审核、发布
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param logicIds
	 *            对象ID，多id使用英文逗号分隔
	 * @param status
	 *            状态
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class })
	public void updateStatus(final String organCode, final long organLogicId, final String logicIds,
			final String status) {
		if (StringUtils.isEmpty(organCode) || StringUtils.isEmpty(logicIds) || StringUtils.isEmpty(status)) {
			return;
		}
		final String[] logicIdArr = logicIds.split(StringConstants.STRING_SPLIT_FLAG_3);
		if (logicIdArr == null) {
			return;
		}
		ArticleObj obj = null;
		for (final String logicId : logicIdArr) {
			if (StringUtils.isNotEmpty(logicId)) {
				obj = articleDao.getByLogicId(organCode, organLogicId, Long.parseLong(logicId));
				if (obj == null) {
					continue;
				}

				if (ArticleObj.STATUS_0.equalsIgnoreCase(status)) {
					// 待编辑
					obj.setIsPub(StringConstants.NO);
					obj.setPubTime(null);
					articleLogService.save(organCode, organLogicId,
							new ArticleLogObj(obj.getLogicId(), ArticleLogObj.STEP_ADD));
				} else if (ArticleObj.STATUS_1.equalsIgnoreCase(status)) {
					// 待校对
					obj.setIsPub(StringConstants.NO);
					obj.setPubTime(null);
					articleLogService.save(organCode, organLogicId,
							new ArticleLogObj(obj.getLogicId(), ArticleLogObj.STEP_EDIT));
				} else if (ArticleObj.STATUS_2.equalsIgnoreCase(status)) {
					// 待审核
					obj.setIsPub(StringConstants.NO);
					obj.setPubTime(null);
					articleLogService.save(organCode, organLogicId,
							new ArticleLogObj(obj.getLogicId(), ArticleLogObj.STEP_PROOF));
				} else if (ArticleObj.STATUS_3.equalsIgnoreCase(status)) {
					// 已发布
					obj.setIsPub(StringConstants.YES);
					obj.setPubTime(LocalDateTime.now());
					articleLogService.save(organCode, organLogicId,
							new ArticleLogObj(obj.getLogicId(), ArticleLogObj.STEP_APPROVE));
				}
				obj.setStatus(status);
				articleDao.updateById(obj);
			}
		}
	}

	/**
	 * 统计栏目下发布的文章数量
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param columnLogicId
	 *            栏目逻辑ID
	 * @return 数量
	 */
	@Override
	public long countByColumnLogicId(final String organCode, final long organLogicId, final long columnLogicId) {
		if (StringUtils.isEmpty(organCode)) {
			return 0;
		}

		return articleDao.countByColumnLogicId(organCode, organLogicId, columnLogicId);
	}

	/**
	 * 添加访问量
	 *
	 * @param request
	 *            HttpServletRequest
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param logicId
	 *            对象ID
	 * @param visitor
	 *            访问者
	 * @return 当前数量
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class })
	public int addPageViews(final HttpServletRequest request, final String organCode, final long organLogicId,
			final long logicId, final String visitor) {
		if (StringUtils.isEmpty(organCode)) {
			return 0;
		}

		final ArticleObj obj = articleDao.getByLogicId(organCode, organLogicId, logicId);
		if (obj == null) {
			return 0;
		}
		obj.setPageViews(obj.getPageViews() + 1);
		articleDao.updateById(obj);

		if (articleViewService != null) {
			final String ip = WebUtil.getIpAddr(request);
			articleViewService.save(organCode, organLogicId, new ArticleViewObj(logicId, ArticleViewObj.VIEW_FROM_PC,
					LocalDateTime.now(), visitor, ip, WebUtil.getMACAddress(ip)));
		}
		return obj.getPageViews();
	}

	/**
	 * 添加点赞量
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param logicId
	 *            对象ID
	 * @return 当前数量
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class })
	public int addPageGoods(final String organCode, final long organLogicId, final long logicId) {
		if (StringUtils.isEmpty(organCode)) {
			return 0;
		}

		final ArticleObj obj = articleDao.getByLogicId(organCode, organLogicId, logicId);
		if (obj == null) {
			return 0;
		}
		obj.setPageGoods(obj.getPageGoods() + 1);
		articleDao.updateById(obj);
		return obj.getPageGoods();
	}

	/**
	 * 根据ID删除对象
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param logicId
	 *            对象ID
	 */
	@Override
	@OperationLog(method = LogType.DELETE, msg = "文章")
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class })
	public void deleteByLogicId(final String organCode, final long organLogicId, final long logicId) {
		if (StringUtils.isEmpty(organCode)) {
			return;
		}

		articleDao.deleteByLogicId(organCode, organLogicId, logicId);
		articleInfoDao.deleteByArticleLogicId(organCode, organLogicId, logicId);
		articleExtDao.deleteByArticleLogicId(organCode, organLogicId, logicId);
	}

	/**
	 * 批量删除对象
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param logicIds
	 *            对象ID，多id使用英文逗号分隔
	 */
	@Override
	public void deleteByBatch(final String organCode, final long organLogicId, final String logicIds) {
		if (StringUtils.isEmpty(organCode) || StringUtils.isEmpty(logicIds)) {
			return;
		}
		final String[] logicIdArr = logicIds.split(StringConstants.STRING_SPLIT_FLAG_3);
		if (logicIdArr == null) {
			return;
		}
		for (final String logicId : logicIdArr) {
			if (StringUtils.isEmpty(logicId)) {
				continue;
			}
			this.deleteByLogicId(organCode, organLogicId, Long.parseLong(logicId));
		}
	}

	/**
	 * 根据id查询对象
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param logicId
	 *            对象logicId
	 * @return 对象
	 */
	@Override
	public ArticleObj getByLogicId(final String organCode, final long organLogicId, final long logicId) {
		if (StringUtils.isEmpty(organCode)) {
			return null;
		}
		final ArticleObj obj = articleDao.getByLogicId(organCode, organLogicId, logicId);
		if (obj == null) {
			return null;
		}
		ArticleInfoObj info = articleInfoDao.getByArticleLogicId(organCode, organLogicId, obj.getLogicId());
		if (info == null) {
			info = new ArticleInfoObj();
			info.setOrganCode(obj.getOrganCode());
			info.setOrganLogicId(obj.getOrganLogicId());
			info.setArticleLogicId(obj.getLogicId());
		}
		obj.setInfo(info);
		ArticleExtObj ext = articleExtDao.getByArticleLogicId(organCode, organLogicId, obj.getLogicId());
		if (ext == null) {
			ext = new ArticleExtObj();
			ext.setOrganCode(obj.getOrganCode());
			ext.setOrganLogicId(obj.getOrganLogicId());
			ext.setArticleLogicId(obj.getLogicId());
		}
		obj.setExt(ext);
		return obj;
	}

	/**
	 * 查询所有对象
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @return 对象集合
	 */
	@Override
	public List<ArticleObj> findAll(final String organCode, final long organLogicId) {
		if (StringUtils.isEmpty(organCode)) {
			return null;
		}
		return articleDao.findAll(organCode, organLogicId);
	}

	/**
	 * 根据条件查询
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param property
	 *            参数。其中isLike:Boolean 是否模糊查询
	 * @return 集合
	 */
	@Override
	public List<ArticleObj> search(final String organCode, final long organLogicId, Map<String, Object> property) {
		if (StringUtils.isEmpty(organCode)) {
			return null;
		}
		if (property == null) {
			property = new HashMap<String, Object>(1);
			property.put("organLogicId", organLogicId);
		}
		final QueryWrapper<ArticleObj> queryWrapper = new QueryWrapper<ArticleObj>();
		replaceProperty(property);
		createSql(property, queryWrapper, new String[] { "ARTICLE_ORDER", "UPDATE_TIME" });
		return articleDao.selectList(queryWrapper);
	}

	/**
	 * 根据条件查询
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param offset
	 *            当前页数
	 * @param limit
	 *            分页长度
	 * @param property
	 *            参数。其中isLike:Boolean 是否模糊查询
	 * @return 返回Map
	 */
	@Override
	public IPage<ArticleObj> search(final String organCode, final long organLogicId, final int offset, final int limit,
			Map<String, Object> property) {
		if (StringUtils.isEmpty(organCode)) {
			return null;
		}
		if (property == null) {
			property = new HashMap<String, Object>(1);
			property.put("organLogicId", organLogicId);
		}
		final IPage<ArticleObj> page = new Page<ArticleObj>(offset, limit);
		final QueryWrapper<ArticleObj> queryWrapper = new QueryWrapper<ArticleObj>();
		replaceProperty(property);
		createSql(property, queryWrapper, new String[] { "ARTICLE_ORDER", "UPDATE_TIME" });
		return articleDao.selectPage(page, queryWrapper);
	}

	/**
	 * 根据条件查询
	 *
	 * @param organCode
	 *            租户编码
	 * @param organLogicId
	 *            租户逻辑ID
	 * @param offset
	 *            当前页数
	 * @param limit
	 *            分页长度
	 * @param property
	 *            参数。其中isLike:Boolean 是否模糊查询
	 * @return 返回Map
	 */
	@Override
	public Map<String, Object> searchByColumn(final String organCode, final long organLogicId, final int offset,
			final int limit, Map<String, Object> property) {
		if (StringUtils.isEmpty(organCode)) {
			return null;
		}
		if (property == null) {
			property = new HashMap<String, Object>(1);
			property.put("organLogicId", organLogicId);
		}

		final com.baomidou.mybatisplus.plugins.Page<ArticleObj> page = new com.baomidou.mybatisplus.plugins.Page<ArticleObj>(
				offset, limit);

		final Map<String, Object> map = new HashMap<String, Object>(2);
		map.put(GlobalConstants.PAGE_RESULTS, articleDao.searchByOrgan(page, organCode, organLogicId, property));
		map.put(GlobalConstants.PAGE_COUNT, articleDao.countByOrgan(organCode, organLogicId, property));
		return map;
	}

	/**
	 * 复制信息
	 *
	 * @param fromObj
	 *            原信息
	 * @param toObj
	 *            新信息
	 */
	private void setForm(final ArticleObj fromObj, final ArticleObj toObj) {
		toObj.setOrganLogicId(fromObj.getOrganLogicId());
		toObj.setTitle(StringUtils.trimToEmpty(fromObj.getTitle()));
		toObj.setImg(StringUtils.trimToEmpty(fromObj.getImg()));
		toObj.setSubhead(StringUtils.trimToEmpty(fromObj.getSubhead()));
		toObj.setSummary(StringUtils.trimToEmpty(fromObj.getSummary()));
		toObj.setArtKey(StringUtils.trimToEmpty(fromObj.getArtKey()));
		toObj.setMyOrder(fromObj.getMyOrder());
		toObj.setIsPub(StringUtils.trimToEmpty(fromObj.getIsPub()));
		toObj.setStatus(StringUtils.trimToEmpty(fromObj.getStatus()));
		toObj.setQoriginal(StringUtils.trimToEmpty(fromObj.getQoriginal()));
		toObj.setPageViews(fromObj.getPageViews());
		toObj.setPageGoods(fromObj.getPageGoods());
		toObj.setWriter(StringUtils.trimToEmpty(fromObj.getWriter()));
		toObj.setUserId(fromObj.getUserId());
		toObj.setUserName(StringUtils.trimToEmpty(fromObj.getUserName()));
		toObj.setOrgId(fromObj.getOrgId());
		toObj.setOrgName(StringUtils.trimToEmpty(fromObj.getOrgName()));
		toObj.setIsTopline(StringUtils.trimToEmpty(fromObj.getIsTopline()));
		toObj.setIsStick(StringUtils.trimToEmpty(fromObj.getIsStick()));
		toObj.setIsComment(StringUtils.trimToEmpty(fromObj.getIsComment()));
		toObj.setSendTime(fromObj.getSendTime());
		toObj.setEndTime(fromObj.getEndTime());
		toObj.setPubTime(fromObj.getPubTime());
		toObj.setSyncMiniSite(StringUtils.trimToEmpty(fromObj.getSyncMiniSite()));
		toObj.setSyncApp(StringUtils.trimToEmpty(fromObj.getSyncApp()));
		toObj.setColumnLogicId(fromObj.getColumnLogicId());
		toObj.setColumnName(StringUtils.trimToEmpty(fromObj.getColumnName()));
		if (ArticleObj.STATUS_3.equals(toObj.getStatus())) {
			// 发布状态
			toObj.setIsPub(StringConstants.YES);
			toObj.setPubTime(LocalDateTime.now());
		} else {
			// 非发布状态
			toObj.setIsPub(StringConstants.NO);
			toObj.setPubTime(null);
		}
	}

	/**
	 * 将对象属性替换成数据库列
	 *
	 * @param property
	 *            参数
	 */
	private void replaceProperty(final Map<String, Object> property) {
		if (property != null) {
			if (property.containsKey("organLogicId")) {
				property.put("ORGAN_LOGIC_ID", property.get("organLogicId"));
				property.remove("organLogicId");
			}
			if (property.containsKey("title")) {
				property.put("ARTICLE_TITLE", property.get("title"));
				property.remove("title");
			}
			if (property.containsKey("img")) {
				property.put("ARTICLE_IMG", property.get("img"));
				property.remove("img");
			}
			if (property.containsKey("subhead")) {
				property.put("ARTICLE_SUBHEAD", property.get("subhead"));
				property.remove("subhead");
			}
			if (property.containsKey("summary")) {
				property.put("ARTICLE_SUMMARY", property.get("summary"));
				property.remove("summary");
			}
			if (property.containsKey("artKey")) {
				property.put("ARTICLE_KEY", property.get("artKey"));
				property.remove("artKey");
			}
			if (property.containsKey("myOrder")) {
				property.put("ARTICLE_ORDER", property.get("myOrder"));
				property.remove("myOrder");
			}
			if (property.containsKey("isPub")) {
				property.put("IS_PUB", property.get("isPub"));
				property.remove("isPub");
			}
			if (property.containsKey("status")) {
				property.put("ARTICLE_STATUS", property.get("status"));
				property.remove("status");
			}
			if (property.containsKey("qoriginal")) {
				property.put("ARTICLE_QORIGINAL", property.get("qoriginal"));
				property.remove("qoriginal");
			}
			if (property.containsKey("pageViews")) {
				property.put("PAGE_VIEWS", property.get("pageViews"));
				property.remove("pageViews");
			}
			if (property.containsKey("pageGoods")) {
				property.put("PAGE_GOODS", property.get("pageGoods"));
				property.remove("pageGoods");
			}
			if (property.containsKey("writer")) {
				property.put("ARTICLE_WRITER", property.get("writer"));
				property.remove("writer");
			}
			if (property.containsKey("userId")) {
				property.put("USER_ID", property.get("userId"));
				property.remove("userId");
			}
			if (property.containsKey("userName")) {
				property.put("USER_NAME", property.get("userName"));
				property.remove("userName");
			}
			if (property.containsKey("orgId")) {
				property.put("ORG_ID", property.get("orgId"));
				property.remove("orgId");
			}
			if (property.containsKey("orgName")) {
				property.put("ORG_NAME", property.get("orgName"));
				property.remove("orgName");
			}
			if (property.containsKey("isTopline")) {
				property.put("IS_TOPLINE", property.get("isTopline"));
				property.remove("isTopline");
			}
			if (property.containsKey("isStick")) {
				property.put("IS_STICK", property.get("isStick"));
				property.remove("isStick");
			}
			if (property.containsKey("isComment")) {
				property.put("IS_COMMENT", property.get("isComment"));
				property.remove("isComment");
			}
			if (property.containsKey("sendTime")) {
				property.put("SEND_TIME", property.get("sendTime"));
				property.remove("sendTime");
			}
			if (property.containsKey("endTime")) {
				property.put("END_TIME", property.get("endTime"));
				property.remove("endTime");
			}
			if (property.containsKey("pubTime")) {
				property.put("PUB_TIME", property.get("pubTime"));
				property.remove("pubTime");
			}
			if (property.containsKey("syncMiniSite")) {
				property.put("SYNC_MINI_SITE", property.get("syncMiniSite"));
				property.remove("syncMiniSite");
			}
			if (property.containsKey("syncApp")) {
				property.put("SYNC_APP", property.get("syncApp"));
				property.remove("syncApp");
			}
			if (property.containsKey("columnLogicId")) {
				property.put("COLUMN_LOGIC_ID", property.get("columnLogicId"));
				property.remove("columnLogicId");
			}
			if (property.containsKey("columnName")) {
				property.put("COLUMN_NAME", property.get("columnName"));
				property.remove("columnName");
			}
			if (property.containsKey("createPerson")) {
				property.put("CREATE_PERSON", property.get("createPerson"));
				property.remove("createPerson");
			}
			if (property.containsKey("createPersonId")) {
				property.put("CREATE_PERSON_ID", property.get("createPersonId"));
				property.remove("createPersonId");
			}
			if (property.containsKey("createTime")) {
				property.put("CREATE_TIME", property.get("createTime"));
				property.remove("createTime");
			}
			if (property.containsKey("updatePerson")) {
				property.put("UPDATE_PERSON", property.get("updatePerson"));
				property.remove("updatePerson");
			}
			if (property.containsKey("updateTime")) {
				property.put("UPDATE_TIME", property.get("updateTime"));
				property.remove("updateTime");
			}
		}
	}
}